<template>
  <el-table :data="articleData">
    <el-table-column prop="title" label="标题"/>
    <el-table-column prop="data" label="链接">
        <template #default="scope">
            <el-link href="scope.row.data" target="_blank">{{scope.row.data}}</el-link>
        </template>
</el-table-column>
<el-table-column fixed="right" label="编辑" width="85px">
    <template #default="scope">
        <el-button type="text" size="small" @click="deleteData(scope.row.id)">删除</el-button>
        <el-button type="text" size="small" @click="editData(scope.row.id)">修改</el-button>
      </template>
</el-table-column>
</el-table>
</template>

<script>
    import message from '../modular/message.js'
    import axios from 'axios'
    export default {
        data() {
            return {
                articleData: [],
            }
        },
        methods: {
            obtainData() {
                axios.get('/article/list').then(res => {
                    this.articleData = res.data.body;
                })
            },
            deleteData(id) {
                axios.delete(`/article/delete/${id}`).then(res => {
                    console.log(res)
                    if (res.data.Code == 200) {
                        message(res.data.message, 'success')
                    } else {
                        message(res.data.message, 'error')
                    }
                    this.obtainData()
                })
            },
            editData(id) {
                this.$router.push(`/article/edit/${id}`)
            }
        },
        created() {
            this.obtainData()
        }
    }
</script>